package cvo.pro4.chess.client.entities;

import cvo.pro4.chess.client.entities.movement.IMovementStrategy;
import cvo.pro4.chess.client.exceptions.IllegalCoordinatesException;



public abstract class  Piece implements IMovementStrategy {
	private Integer id;
	private Boolean status;
	private Color color;
	private String name;
	
	
	
	public Piece(Color color){		
		this.color = color;
		this.id= this.hashCode();
		
	}
	
	
	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}

	public Boolean isActive(){
		return this.status;
	}
	
	public void setActive(){	
		this.status = true;
	}
	
	public void setInactive(){
		this.status = false;
	}
	
	
	
	public Integer getId() {
		return id;
	}


	public Color getColor(){
		return this.color;
	}	
	
	public BoardCoordinates getCurrentPosition() throws IllegalCoordinatesException{
		return Game.getGame().getBoard().getLocationOfPiece(this);
	}


	@Override
	public String toString(){
		return this.getClass().getName();
	}
	
	public void move(BoardCoordinates destination) throws IllegalCoordinatesException{
				
		if(getCurrentPosition().equals(destination)){
			//nothing moved at all > do nothing
			return;
		}
		
		if(getPossibleMoves().contains(destination)){
			Game.getGame().getBoard().removePiece(this);
			Game.getGame().getBoard().setPieceAtLocation(destination, this);
//			Game.getGame().getBoard().getTile(this).removePiece();
//			Game.getGame().getBoard().getTile(this).setPiece(this);
		}
	}
	
	@Override
	public boolean equals(Object o){
		if(o instanceof Piece){
			Piece other = (Piece) o;
			if(this.id.equals(other.id)){
				return true;
			}			
		}
		return false;

	}
	
}
